function formatCarouselRepo (repo) {
    if (repo.loading) return repo.text;
    var markup =repo.name;
    return markup;
  }

  function formatCarouselRepoSelection (repo) {
    return repo.name || repo.text;
  }
  var $carouselSelect;
  function initSelect2(selectId){
		$.fn.modal.Constructor.prototype.enforceFocus=function(){};//此行代码解决select2在模态窗口无法输入的bug
		$carouselSelect=$("#"+selectId).select2({
			allowClear: true,
			language: "zh-CN",
		    ajax: {
		      url: "cms/carousel/query.htm",
		      dataType: 'json',
		      delay: 250,
		      data: function (params) {
		    	  params["page"]=1;
		        return {
		          limit:100,
		          name: params.term, // search term
		          offset: params.page
		        };
		      },
		      processResults: function (data, params) {
		        // parse the results into the format expected by Select2
		        // since we are using custom formatting functions we do not need to
		        // alter the remote JSON data, except to indicate that infinite
		        // scrolling can be used
		        params.page = params.page || 1;
		        
		        var l=data.rows.length;
                 for(var i=0;i<l;i++){
                	 data.rows[i].id=data.rows[i].code;
                	 data.rows[i]["text"]=data.rows[i].name;
                 }
		         return {
		          results: data.rows,
		          pagination: {
		            more: (params.page * 30) < data.totalCount
		          }
		        };
		      },
		      cache: true
		    },
		    escapeMarkup: function (markup) { return markup; },
		    minimumInputLength: 1,
		    templateResult: formatCarouselRepo,
		    templateSelection: formatCarouselRepoSelection
		  });
			$(".select2-container--default").css({"width":"100%"});
  }

  function insertCarouselSelect(){
	  var name=$("#select2-carouseSelect-container").text();
	  editor.insertHtml('<input value="轮播{'+name+'}" class="carouse_code" code="'+$carouselSelect.val()+'" />');
	  $("#carouselModal").modal("hide");
  }